<?php

/**
 * skill_comment actions.
 *
 * @package    jiazhang
 * @subpackage skill_comment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class skill_commentActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    $skill_id = (int)$request->getParameter('skill_id',0);
    $block_ids = Doctrine::getTable("StepBlock")->createQuery()->where('skill_id = ?',$skill_id)->execute()->toKeyValueArray('id', 'id');
//    $this->comments = Doctrine::getTable('BlockComment')->createQuery()->whereIn('block_id',$block_ids)->execute();
    
        $dql = Doctrine::getTable('BlockComment')->createQuery()->whereIn('block_id',$block_ids);
        $page = $request->getParameter('page',1);
        $this->pager = new sfDoctrinePager('BlockComment',30);
        $this->pager->setQuery($dql);
        $this->pager->setPage($page);
        $this->pager->init();
    
  }
  
  public function executeDel(sfWebRequest $request)
  {
      $this->forward404Unless($article = Doctrine::getTable('BlockComment')->findOneById($id = $request->getParameter('id',0)));
      $article->delete();
      Doctrine::getTable('BlockComment')->createQuery()->where('parent_id = ?',$id)->delete()->execute();
      $this->getUser()->setFlash('success', '删除成功！');
      $this->redirect('skill_comment/index');
  }
}
